#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 210;
const int M = 4e4+10;

int n,m,tim,dfn[N],low[N],scc[N],nodenum,cnt,h[N],stk[N],top;
bool vis[N];
struct edge{int v,nxt;}e[M<<1];
void link(int x,int y){e[++cnt] = (edge){y,h[x]};h[x] = cnt;}

void dfs(int x){
	dfn[x] = low[x] = ++tim; vis[x] = 1; stk[++top] = x;
	for(int i = h[x],y;i;i = e[i].nxt){
		if(!dfn[y = e[i].v]) dfs(y),low[x] = min(low[x],low[y]);
		else if(vis[y]) low[x] = min(low[x],dfn[y]);
	}
	if(low[x] == dfn[x]){
		int y; ++nodenum;
		do{
			y = stk[top--]; vis[y] = 0; scc[y] = nodenum;
		}while(y != x);
	}
}

void solve(){
	n = in,m = in; tim = 0;
	memset(h,0,sizeof(h)); memset(dfn,0,sizeof(dfn)); memset(low,0,sizeof(low)); memset(scc,0,sizeof(scc)); nodenum = 0;cnt = 0;
	memset(vis,0,sizeof(vis));
	for(int i = 1;i <= m;i++){
		char ch = getchar(); while(ch != 'm' && ch != 'h') ch = getchar(); int cc0 = (ch == 'm') * n + in;
		ch = getchar(); while(ch != 'm' && ch != 'h') ch = getchar(); int cc1 = (ch == 'h') * n + in;
		link(cc0,cc1); cc0 = cc0 > n ? cc0 - n : cc0 + n; cc1 = cc1 > n ? cc1 - n : cc1 + n; link(cc1,cc0);
	}
	for(int i = 1;i <= n<<1;i++) if(!dfn[i]) dfs(i);
	for(int i = 1;i <= n;i++) if(scc[i] == scc[i+n]) return puts("BAD"),void();
	return puts("GOOD"),void();
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	int test = in;while(test--) solve();
	return 0;
}

